package com.tk.exam.dao;

import com.github.pagehelper.PageInfo;
import com.tk.exam.domain.TkQuestionCategory;
import com.tk.exam.domain.TkQuestionCategoryExample;
import com.tk.exam.domain.TkQuestions;
import com.tk.exam.mapper.TkQuestionCategoryMapper;
import com.tk.exam.mapper.TkQuestionsMapper;
import com.tk.exam.vo.question.TkQuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Repository
public class TkQuesCategoryDao {

    @Autowired
    private TkQuestionCategoryMapper tkQuesCategoryMapper;

    public PageInfo<TkQuestionCategory> selectQuesCategoryWithPage() {
        TkQuestionCategoryExample example = new TkQuestionCategoryExample();
        return new PageInfo<TkQuestionCategory>(tkQuesCategoryMapper.selectByExample(example));
    }
    @Transactional
    public TkQuestionCategory save(TkQuestionCategory tkQuestionCategory) {
        Integer id;
        Date date = new Date();
        if (tkQuestionCategory.getId() != null) {
            tkQuestionCategory.setUpdateTime(date);
            id = this.tkQuesCategoryMapper.updateByPrimaryKeySelective(tkQuestionCategory);
        } else {
            tkQuestionCategory.setCreateTime(date);
            tkQuestionCategory.setUpdateTime(date);
            id = this.tkQuesCategoryMapper.insert(tkQuestionCategory);
        }
        return this.tkQuesCategoryMapper.selectByPrimaryKey(id);
    }
    public TkQuestionCategory findById(String id){
        return this.tkQuesCategoryMapper.selectByPrimaryKey(Integer.valueOf(id));
    }
}
